<template>
    <div class="qingwu">
        <div class="admin_table_page_title">积分日志</div>
        <div class="unline underm"></div>

        <div class="admin_table_handle_btn">
            <a-button class="admin_delete_btn" type="danger" icon="delete" @click="del">批量删除</a-button>
        </div>

        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false"
                     :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="id">
            </a-table>

            <div class="admin_pagination" v-if="total>0">
                <a-pagination v-model="params.page" :page-size.sync="params.per_page" :total="total" show-less-items/>
            </div>

        </div>
    </div>
</template>
<script>

export default {
    components: {},
    props: {},
    data() {
        return {
            params: {
                page: 1,
                per_page: 30,
                set_id: 0
            },
            total: 0, //总页数
            selectedRowKeys: [], // 被选择的行
            columns: [
                {title: '所属积分设置', dataIndex: 'belong_text'},
                {title: '积分类型', dataIndex: 'type_text'},
                {title: '用户名', dataIndex: 'username'},
                {title: '用户openid', dataIndex: 'openid'},
                {title: '领取积分', dataIndex: 'integral'},
                {title: '积分变化前', dataIndex: 'before_integral'},
                {title: '积分变化后', dataIndex: 'after_integral'},
                {title: '领取时间', dataIndex: 'created_at'},
            ],
            list: [],
            count: [],
        };
    },
    watch: {},
    computed: {},
    methods: {
        search(params) {
            let page = this.params.page;
            let per_page = this.params.per_page;
            this.params = params;
            this.params.page = page;
            this.params.per_page = per_page;
            this.onload();
        },
        // 选择框被点击
        onSelectChange(selectedRowKeys) {
            this.selectedRowKeys = selectedRowKeys;
        },
        // 删除
        del() {
            if (this.selectedRowKeys.length == 0) {
                return this.$message.error('未选择数据.');
            }
            this.$confirm({
                title: '你确定要删除选择的数据？',
                content: '确定删除后无法恢复.',
                okText: '是',
                okType: 'danger',
                cancelText: '取消',
                onOk: () => {
                    let ids = this.selectedRowKeys.join(',');
                    this.$delete(this.$api.IntegralSet + '/' + ids).then(res => {
                        if (res.code == 200) {
                            this.onload();
                            this.$message.success('删除成功');
                        } else {
                            this.$message.error(res.msg)
                        }
                    });

                },
            });
        },
        onload() {
            // 判断你是否是编辑
            if (!this.$isEmpty(this.$route.params.set_id)) {
                console.log(this.$route.params.set_id);
                this.params.set_id = this.$route.params.set_id;
            }
            this.$get(this.$api.IntegralLog, this.params).then(res => {
                this.list = res.data.data;
                this.count = res.data.count;
                this.total = res.data.total;
            });
        },
    },
    created() {
        this.onload();
    },
    mounted() {
    }
};
</script>
<style lang="scss" scoped>

</style>
